home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI2000 / TI2534.ASC < prev    next >
Text File  |  1994-09-20  |  5KB  |  217 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Pascal                                 NUMBER  :  2534
  8.   VERSION  :  All
  9.        OS  :  Windows
  10.      DATE  :  July 11, 1994                            PAGE  :  1/4
  11.  
  12.     TITLE  :  Getting / Setting diskette serial # under Windows.
  13.  
  14.  
  15.  
  16.  
  17. (*
  18. This example demonstrates how to get/set the volume serial
  19. number of a diskette under Windows or DOS Protected Mode.
  20. This sample demonstrates two important interrupts: Int $21,
  21. service $69 (Get/Set media info) and Int $31 (simulate real
  22. mode interrupt from DPMI).
  23.  
  24. NOTE: To use the following code under DPMI instead of Windows,
  25. replace all of the occurances of "WinProcs" with "WinAPI"
  26. in the USES clauses.
  27. *)
  28. unit MediaID;
  29. { Use this unit in your program }
  30.  
  31. Interface
  32.  
  33. Type
  34.   PMediaID = ^TMediaID;
  35.   TMediaID = Record
  36.     InfoLvl:   Word;
  37.     SerialNum: Longint;
  38.     VolLabel:  Array[0..10] of Char;
  39.     FileSys:   Array [0..7] of Char;
  40.   end;
  41.  
  42.   TRMCS = record     { Real mode call structure }
  43.     DI, SI, BP, Reserved, BX, DX, CX, AX : Longint;
  44.     Flags, ES, DS, FS, GS, IP, SP, SS: Word;
  45.   end;
  46.  
  47.  
  48. FUNCTION GetMediaInfo( Drive: WORD; MID: PMediaID ): Boolean;
  49. FUNCTION SetMediaInfo( Drive: WORD; MID: PMediaID ): Boolean;
  50.   { MID should be a real mode pointer, that is, segment:offset }
  51.   { Allocate memory for MID pointer using GlobalDOSAlloc }
  52.   { Drive:  0=default, 1=A, 2=B, etc. }
  53.  
  54. Implementation
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   PRODUCT  :  Pascal                                 NUMBER  :  2534
  68.   VERSION  :  All
  69.        OS  :  Windows
  70.      DATE  :  July 11, 1994                            PAGE  :  2/4
  71.  
  72.     TITLE  :  Getting / Setting diskette serial # under Windows.
  73.  
  74.  
  75.  
  76.  
  77.  
  78. uses WinAPI;
  79.  
  80. var
  81.   R: TRMCS;
  82.  
  83. function GetMediaInfo( Drive: WORD; MID: PMediaID ): Boolean;
  84. var
  85.   ErrorFlag : byte;
  86. begin
  87.   GetMediaInfo := True;
  88.   R.BX := Drive;   { 0 = Default, 1 = A, 2 = B, etc }
  89.   R.DS := HiWord(Longint(MID));  { Segment (not selector) of MID }
  90.   R.DX := LoWord(Longint(MID));  { Offset of MID }
  91.   R.AX := $6900;  { Real mode service $69, subfunc 0 }
  92.   asm
  93.     mov bx, 0021h { set flags to $00, Real mode interrupt $21 }
  94.     mov cx, 0     { copy 0 words from protected mode stack }
  95.     mov ax, seg R
  96.     mov es, ax       { selector of real mode call structure }
  97.     mov di, offset R { offset of real mode call structure }
  98.     mov ax, 0300h    { DPMI simulate real mode interrupt }
  99.     int 31h
  100.     pushf            { push flags onto stack }
  101.     pop   bx         { pop flags into bx }
  102.     test  bx, 0      { error check: is CF flag 0? }
  103.     je    @@done     { if so, then there was no error }
  104.   @@error:
  105.     mov   ErrorFlag, 1  { set error flag }
  106.   @@done:
  107.   end;
  108.   if ErrorFlag = 1 then
  109.     GetMediaInfo := False;  { return False on error }
  110. end;
  111.  
  112. function SetMediaInfo( Drive: WORD; MID: PMediaID ): Boolean;
  113. var
  114.   ErrorFlag : byte;
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.   PRODUCT  :  Pascal                                 NUMBER  :  2534
  128.   VERSION  :  All
  129.        OS  :  Windows
  130.      DATE  :  July 11, 1994                            PAGE  :  3/4
  131.  
  132.     TITLE  :  Getting / Setting diskette serial # under Windows.
  133.  
  134.  
  135.  
  136.  
  137. begin
  138.   SetMediaInfo := True;
  139.   R.BX := Drive;   { 0 = Default, 1 = A, 2 = B, etc }
  140.   R.DS := HiWord(Longint(MID));  { Segment of MID }
  141.   R.DX := LoWord(Longint(MID));  { Offset of MID }
  142.   R.AX := $6901;  { Real mode service $69, subfunc 1 }
  143.   asm
  144.     mov bx, 0021h { Real mode interrupt $21 }
  145.     mov cx, 0
  146.     mov ax, seg R
  147.     mov es, ax       { real mode selector call structure }
  148.     mov di, offset R { offset of real mode call structure }
  149.     mov ax, 0300h    { DPMI simulate real mode interrupt }
  150.     int 31h
  151.     pushf            { push flags onto stack }
  152.     pop   bx         { pop flags into bx }
  153.     test  bx, 0      { error check: is CF flag 0? }
  154.     je    @@done     { if so, then there was no error }
  155.   @@error:
  156.     mov   ErrorFlag, 1  { set error flag }
  157.   @@done:
  158.   end;
  159.   if ErrorFlag = 1 then
  160.     SetMediaInfo := False;  { return False on error }
  161. end;
  162.  
  163. begin
  164. end.   {*** End of MediaID unit ***}
  165.  
  166. Here is a small sample program that demonstrates
  167. how to use the MediaID unit:
  168.  
  169. program DiskInfo;
  170.  
  171. uses MediaID, WinProcs, WinCRT;
  172.  
  173. var
  174.   SReal, SProt : PMediaId;
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.   PRODUCT  :  Pascal                                 NUMBER  :  2534
  188.   VERSION  :  All
  189.        OS  :  Windows
  190.      DATE  :  July 11, 1994                            PAGE  :  4/4
  191.  
  192.     TITLE  :  Getting / Setting diskette serial # under Windows.
  193.  
  194.  
  195.  
  196.  
  197.   LongHandle : Longint;
  198. begin
  199.   { allocate some lower memory }
  200.   LongHandle := GlobalDOSAlloc(SizeOf(TMediaID)); 
  201.   { real mode pointer }
  202.   SReal := PMediaID(Ptr(HiWord(LongHandle), 0)); 
  203.   { protected mode pointer }
  204.   SProt := PMediaID(Ptr(LoWord(LongHandle), 0)); 
  205.   GetMediaInfo(3, SReal);      { call function }
  206.   writeln(SProt^.SerialNum);   { write serial # }
  207.   GlobalDOSFree(LoWord(LongHandle)); { free allocated memory }
  208. end. {*** End of DiskInfo program ***}
  209.  
  210.  
  211.  
  212.  
  213. DISCLAIMER: You have the right to use this technical information
  214. subject to the terms of the No-Nonsense License Statement that
  215. you received with the Borland product to which this information
  216. pertains.
  217.